<?php include(FULL_HTML_VIEWS_PATH . '/common/page_header.php'); ?>
<link href="css/amap.Default.css" rel="stylesheet">
<?php if (isset($debug_page) && $debug_page === TRUE): ?>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="css/main.css" rel="stylesheet">
<?php endif; ?>
<div class="page_loading" style="display: none;"></div>

<?php include(FULL_HTML_VIEWS_PATH . '/common/page_menu.php'); ?>
<div class="main-content">
    <div class="main-content-inner">
        <div class="page-content">
            <div class="row">
                <div class="col-sm-12">
                    <div class="breadcrumbs" id="breadcrumbs">
                        <ul class="breadcrumb">
                            <?php include(FULL_HTML_VIEWS_PATH . '/common/page_ur_here.php'); ?>
                        </ul>
                    </div>
                </div>
            </div>
            <h2 class="sub-header">
                <?php echo $page_title; ?>
                <a href="<?php echo site_url("$my_router"); ?>" class="btn btn-sm btn-white pull-right"><span class="glyphicon glyphicon-backward"></span> 返回列表</a>
            </h2>
            <div class="row">
                <div class="col-sm-12">
                    <ul class="nav nav-tabs" role="tablist" style="margin:0px 5px;">
                        <li class="active"><a href="#base" role="tab" data-toggle="tab">基本信息</a></li>
                    </ul>
                    <div class="panel panel-default" style="margin-top:-2px;">
                        <div class="panel-heading hide" style=" margin:0px 1px;">
                            <span class="glyphicon glyphicon-list"></span> &nbsp;&nbsp;
                        </div>
                        <div class="panel-body tab-content">
                            <div id="base" class="tab-pane active">
                                <form data-action="ajaxPageForm" action="<?php echo site_url("$my_router/post"); ?>" class="form-horizontal" role='form' method="post" autocomplete="off">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">角色名称</label>
                                        <div class="col-sm-6">
                                            <input class="col-xs-10" type="text" data-demand="required" value="<?php isset_echo($info, "role_name"); ?>" name="role_name"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">备注</label>
                                        <div class="col-sm-6">
                                            <textarea style="resize: none;" class="col-xs-10" rows="3" name="remark"><?php isset_echo($info, "remark"); ?></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">权限</label>
                                        <div class="col-sm-6 privilege">
                                            <?php foreach (config_item('page_menu') as $k => $v): ?>
                                                <div style="border: 1px solid #989898;margin-bottom: 10px;padding: 5px;">
                                                    <tr>
                                                        <label>
                                                            <input <?php echo in_array($v['pri_id'], $info['privilege_ids']) ? 'checked' : ''; ?> name="privilege_ids[]" class="level1" type="checkbox" value="<?php echo $v['pri_id']; ?>"><?php echo $v['title'] ?>
                                                        </label>
                                                    </tr>
                                                    <?php if (isset($v['child_list']) && !empty($v['child_list'])): ?>
                                                        <div style="margin-left: 30px;">
                                                            <?php foreach ($v['child_list'] as $k2 => $v2): ?>
                                                                <label style="display:block;">
                                                                    <input <?php echo in_array($v2['pri_id'], $info['privilege_ids']) ? 'checked' : ''; ?> class="level2" name="privilege_ids[]" type="checkbox" value="<?php echo $v2['pri_id']; ?>"><?php echo $v2['title'] ?>
                                                                </label>
                                                                <?php if (isset($v2['child_actions']) && !empty($v2['child_actions'])): ?>
                                                                    <div style="margin-left: 30px;">
                                                                        <?php foreach ($v2['child_actions'] as $k3 => $v3): ?>
                                                                            <label>
                                                                                <input <?php echo in_array($k3, $info['privilege_ids']) ? 'checked' : ''; ?> class="level3" name="privilege_ids[]" type="checkbox" value="<?php echo $k3; ?>"><?php echo $v3; ?>
                                                                            </label>
                                                                        <?php endforeach; ?>
                                                                    </div>
                                                                <?php endif; ?><?php endforeach; ?>
                                                        </div>
                                                    <?php endif; ?>
                                                </div>
                                            <?php endforeach; ?>
                                        </div>
                                    </div>


                                    <!--<div class="form-group">
                                        <label class="col-sm-2 control-label">启用状态</label>
                                        <div class="col-sm-6">
                                            <div class="widget-box widget-color-blue2">
                                                <div class="widget-header">
                                                    <h4 class="widget-title lighter smaller">Choose Categories</h4>
                                                </div>

                                                <div class="widget-body">
                                                    <div class="widget-main padding-8">
                                                        <ul id="tree1"></ul>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>-->

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">启用状态</label>
                                        <div class="col-sm-6">
                                            <label class="radio-inline">
                                                <input type="radio" name="active" value="1" <?php echo (isset($info['active']) && $info['active'] == 1) ? 'checked' : ''; ?>> 启用
                                            </label> <label class="radio-inline">
                                                <input type="radio" name="active" value="0" <?php echo (isset($info['active']) && $info['active'] == 0) ? 'checked' : ''; ?>> 禁用
                                            </label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label id="" class="col-sm-2 control-label sr-only"></label>
                                        <div class="col-sm-3 compact_form">
                                            <button id="adddepartment" type="submit" class="btn btn-lg btn-primary disabled1" data-loading-text="Loading..." autocomplete="off">
                                                <span class="glyphicon glyphicon-save"></span>&nbsp;保存
                                            </button>
                                            <input type="hidden" name="id" id="id" value="<?php isset_echo($info, 'id'); ?>">
                                            <input type="hidden" name="action" id="action" value="<?php echo $form_action; ?>">
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-12 help-block" id="targetUrl"></div>
            </div>
        </div>
    </div>
    <div class="center-block" style="height:30px;"></div>
</div>
<?php include(FULL_HTML_VIEWS_PATH . '/common/page_script.html'); ?><?php include(FULL_HTML_VIEWS_PATH . '/common/page_footer.php'); ?>
<script src="<?php echo full_static_url('bootstrap_ace/js/fuelux/fuelux.tree.js'); ?>"></script>
<script src="<?php echo full_static_url('bootstrap_ace/js/ace/elements.treeview.js'); ?>"></script>
<script type="text/javascript">
    $(function () {

        /*var sampleData = initiateDemoData();//see below

        $('#tree1').ace_tree({
            dataSource: sampleData['dataSource1'],
            multiSelect: true,
            cacheItems: true,
            'open-icon': 'ace-icon tree-minus',
            'close-icon': 'ace-icon tree-plus',
            'selectable': true,
            'selected-icon': 'ace-icon fa fa-check',
            'unselected-icon': 'ace-icon fa fa-times',
            loadingHTML: '<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>'
        });

        function initiateDemoData() {
            var tree_data = {
                'vehicles': {text: 'Vehicles', type: 'folder'}
            }
            tree_data['vehicles']['additionalParameters'] = {
                'children': {
                    'cars': {text: 'Cars', type: 'folder'},
                    'motorcycles': {text: 'Motorcycles', type: 'item'},
                    'boats': {text: 'Boats', type: 'item'}
                }
            }
            tree_data['vehicles']['additionalParameters']['children']['cars']['additionalParameters'] = {
                'children': {
                    'classics': {text: 'Classics', type: 'item'},
                    'convertibles': {text: 'Convertibles', type: 'item'},
                    'coupes': {text: 'Coupes', type: 'item'},
                    'hatchbacks': {text: 'Hatchbacks', type: 'item'},
                    'hybrids': {text: 'Hybrids', type: 'item'},
                    'suvs': {text: 'SUVs', type: 'item'},
                    'sedans': {text: 'Sedans', type: 'item'},
                    'trucks': {text: 'Trucks', type: 'item'}
                }
            }

            console.log(tree_data);
            var dataSource1 = function (options, callback) {
                var $data = null
                if (!("text" in options) && !("type" in options)) {
                    $data = tree_data;//the root tree
                    callback({data: $data});
                    return;
                }
                else if ("type" in options && options.type == "folder") {
                    if ("additionalParameters" in options && "children" in options.additionalParameters)
                        $data = options.additionalParameters.children;
                    else $data = {}//no data
                }

                if ($data != null)//this setTimeout is only for mimicking some random delay
                    setTimeout(function () {
                        callback({data: $data});
                    }, parseInt(Math.random() * 500) + 200);

                //we have used static data here
                //but you can retrieve your data dynamically from a server using ajax call
                //checkout examples/treeview.html and examples/treeview.js for more info
            }

            return {'dataSource1': dataSource1}
        }*/


        $('.level1').click(function () {
            var checked_status = $(this).is(':checked');
            $(this).parent().parent().find('.level2').prop("checked", checked_status);
            $(this).parent().parent().find('.level3').prop("checked", checked_status);
        });
        $('.level2').click(function () {
            var checked_status = $(this).is(':checked');
            if (checked_status) {
                $(this).parent().parent().parent().find('.level1').prop("checked", checked_status);
                $(this).parent().next('div').find('.level3').prop("checked", checked_status);
            }
            $(this).parent().next('div').find('.level3').prop("checked", checked_status);
        });
        $('.level3').click(function () {
            var checked_status = $(this).is(':checked');
            if (checked_status) {
                $(this).parent().parent().prev('label').find('.level2').prop("checked", checked_status);
                $(this).parent().parent().parent().parent().find('.level1').prop("checked", checked_status);
            } else {
                $(this).prop("checked", checked_status);
            }
        });
    })
</script>
